package com.hx.springboot1.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.LocaleResolver;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Locale;

/**
 * Author: hx
 * Date: 2021-05-13 11/50
 * Description: Nothing else
 */
@Slf4j
public class MyLocaleResolver implements LocaleResolver {
    @Override
    public Locale resolveLocale(HttpServletRequest httpServletRequest) {
        String language = (String) httpServletRequest.getSession().getAttribute("lan");
        Locale locale = Locale.getDefault();
        log.info("当前页language：{}",language);
        if(language!=null&&!language.equals("")){
            String[] split = language.split("_");
            locale = new Locale(split[0],split[1]);
        }
        return locale;
    }
    @Override
    public void setLocale(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Locale locale) {
    }
}
